//====================================================================================================
// Includes
//====================================================================================================

#include "EnemyJump.h"

#include "Enemy.h"

//====================================================================================================
// Class Definitions
//====================================================================================================

EnemyJump::EnemyJump(Enemy* pOwner)
	: EnemyState(pOwner, "Jump")
{
	// Empty
}

//----------------------------------------------------------------------------------------------------

EnemyJump::~EnemyJump()
{
	// Empty
}

//----------------------------------------------------------------------------------------------------

void EnemyJump::Load(int level)
{
	// fallen, enemy 1
	if ( level == 1 )
		mSprite.Add("enemy01_idle.png");

	// hive, enemy 2
	else if ( level == 2 )
		mSprite.Add("enemy02_idle.png");

	// vex, enemy 3
	else if ( level == 3 )
	{
		mSprite.Add("enemy03_jump01.png");
		mSprite.Add("enemy03_jump02.png");
	}

	// cabal, enemy 4
	else if ( level == 4 )
	{
		mSprite.Add("enemy04_jump01.png");
		mSprite.Add("enemy04_jump02.png");
	}
}

//----------------------------------------------------------------------------------------------------

void EnemyJump::Unload()
{
	mSprite.Unload();
}

//----------------------------------------------------------------------------------------------------

void EnemyJump::Update(float deltaTime)
{
	// Update sprite
	mSprite.Update(deltaTime);
}

//----------------------------------------------------------------------------------------------------

void EnemyJump::Render(const SVector2& offset)
{
	const int kTextureWidth = mSprite.GetWidth();
	const int kTextureHeight = mSprite.GetHeight();
	const SVector2 ownerPos(mpOwner->GetPosition());
	const SVector2 renderPos(ownerPos.x - (kTextureWidth * 0.5f), ownerPos.y - kTextureHeight);
	bool facingLeft = mpOwner->IsFacingLeft();
	mSprite.SetPosition(renderPos - offset);
	mSprite.SetFlipH(facingLeft);
	mSprite.Render();
}

//----------------------------------------------------------------------------------------------------

void EnemyJump::Enter()
{
	mSprite.Play(1.0f, true);
	SVector2 vel(mpOwner->GetVelocity());
	vel.y = -20.0f;
	mpOwner->SetVelocity(vel);
}

//----------------------------------------------------------------------------------------------------

void EnemyJump::Exit()
{
	mSprite.Stop();
	mSprite.Reset();
}

//----------------------------------------------------------------------------------------------------

SRect EnemyJump::GetBoundingBox() const
{
	const SVector2 pos(mpOwner->GetPosition());
	return SRect
	(
		pos.x - 16.0f,
		pos.y - 56.0f,
		pos.x + 16.0f,
		pos.y
	);
}